package com.atguigu.tingshu.album.mapper;

import com.atguigu.tingshu.model.album.TrackInfo;
import com.atguigu.tingshu.query.album.TrackInfoQuery;
import com.atguigu.tingshu.vo.album.TrackListVo;
import com.atguigu.tingshu.vo.album.TrackStatVo;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

@Mapper
public interface TrackInfoMapper extends BaseMapper<TrackInfo> {


    /**
     * MP框架发现参数中包含分页对象，自动完成分页查询（自动查询总记录数，总页数，当前页数据自动封装到Page对象中）
     * @param pageInfo
     * @param trackInfoQuery
     * @return
     */
    Page<TrackListVo> getUserTrackByPage(Page<TrackListVo> pageInfo,@Param("vo") TrackInfoQuery trackInfoQuery);

    /**
     * 修改声音序号
     * @param albumId
     * @param orderNum
     */
    void updateTrackNum(@Param("albumId")Long albumId, @Param("orderNum")Integer orderNum);

    /**
     * 获取声音统计信息
     * @param trackId
     * @return
     */
    @Select("select " +
            "max(if(stat_type='0701', stat_num, 0)) playStatNum, " +
            "max(if(stat_type='0702', stat_num, 0)) collectStatNum, " +
            "max(if(stat_type='0703', stat_num, 0)) praiseStatNum, " +
            "max(if(stat_type='0704', stat_num, 0)) commentStatNum " +
            "from track_stat where track_id = #{trackId} and is_deleted = 0")
    TrackStatVo getTrackStatVo(Long trackId);
}
